feat(tui): add Claude Code-style --fork-session flag to duplicate sessions before continuing (resolves anomalyco#11137)#147
feat(tui): add Claude Code-style --fork-session flag to duplicate sessions before continuing (resolves anomalyco#11137)#147ariane-emory wants to merge 21 commits intodevfrom
Conversation
- Add --fork CLI flag for session forking with --continue or --session - Forked sessions get automatic (fork #N) title suffix via existing Session.fork() - Validate that --fork requires --continue or --session - Applies to both attach mode and bootstrap mode Fixes anomalyco#11137
- Add fork option to Args interface - Add --fork-session flag to TUI command (thread.ts) - Add validation that --fork-session requires --continue or --session - Fork session before navigating when --fork-session is set
Replace verbose if/else if blocks with ternary expressions to match repo style guide preference for const over let. -8 lines total
When using --session with --fork, the app would briefly show the forked session then navigate to a blank screen. Root cause: race condition where reconcile overwrites the newly forked session from the store. Fix: Wait for sync.status to be "complete" before forking, ensuring session list is fully loaded before the fork operation.
|
while I get the spirit of the PR and it's a good way to help users migrating from CC to OC. however what I am thinking here is that this might create two issues:
what would be a better solution IMO:
|
|
@IdrisGit While we probably can't (and likely shouldn't try to) immediately take parity with every feature of Claude Code, this one seems to me to be an easy win where we can both provide (prospective and actual) CC converts with a feature they're accustomed to while simultaneously providing OC users with a genuinely useful feature. It seems like a modest first move in the grand project of giving Claude Code a wedgie and taking its lunch money: gotta start somewhere! The road towards checkmate almost always begins with pushing some pawns about. I'm not entirely certain whether plugins can implement new command line switches for the When CC users ask "can I have my favourite Claude Code feature?, telling them "well, akshually, no you can't because we're OpenCode and we're different, get with the program!" doesn't seem like it's an answer that should satisfy either party. I think that it would be nice to take a step toward increasing the number of cases where we can say "yes, we have that feature too and ours is better" - that's an answer that would be much more satisfying to begin to be able to offer them! |
|
@ariane-emory I get your point, I am just thinking if this fit with OC maintainers, if they are fine with the fact that either they will have to reach parity with CC commands or have some of them, then it's fine, this is actually more natural for the users |
71151ae to
4410d8b
Compare
Remove the alias and make --fork the primary CLI option name. Update args.forkSession references to args.fork.
What does this PR do?
/forkcommand or TUI message modal receive--fork-sessionis correctly paired with either--continueor--sessionopencode runcommands-Fsyntax in lieu of the verbose--fork-session(using a capitalFso as to avoid collision with the--fileoption that is available in the context ofopencode run)Resolves anomalyco#11137.
Supported syntax examples:
opencode --continue --fork--sessionStart the TUI, continuing and forking (duplicating) the last session
opencode -cFSame as previous, but using terse syntax for both switched
opencode run --continue --fork-session "tell me a better joke"Run one prompt, continuing and forking (duplicating) the last session
opencode run --fork-session "tell me a better joke"Same as previous, but using terse syntax for the --continue switch
opencode -F --session ses_3f2424a04ffeu0ZUiE12HfD2OIFork a particular session.
opencode -F --session ses_that_doesnt_existFails gracefully: OpenCode starts, but displays a
Failed to fork sessiontoast.opencode run -F --session ses_that_doesnt_exist "I'm not gonna work."Fails gracefully: an
Error: Session not foundmessage is written to STDERR and an exit code of 1 is used.Questions That Remain Open
Ought we tolerate
--forkas being synonymous with--fork-session?Forgetting to include the
-sessionfragment does seem, to me, like a mistake that a user could easily make, so perhaps it would be prudent to give them a soft landing by accepting as a synonym.This is not implemented presently, but this affordance would be trivial to offer, if it were desired.
How did you verify your code works?
Manual testing,
bun test,bun typecheck: all pass with flying colours so far as I can tell thus far.